﻿using EFCoreTableSplitDemo;
using Microsoft.EntityFrameworkCore;

var connectionString = "server=localhost;port=5432;Database=efcoretablesplit;uid=postgres;pwd=xxx;";
var contextOptions = new DbContextOptionsBuilder<TableSplittingContext>()
    .UseNpgsql(connectionString)
    .Options;
using (var context = new TableSplittingContext(contextOptions))
{
    context.Database.EnsureDeleted();
    context.Database.EnsureCreated();

    context.Add(new Order()
    {
        Name = "aa",
        OrderItems = new List<OrderItem>()
        {
            new OrderItem()
            {
                Product = new Product()
                {
                    Name = "p"
                },
                ProductAttribute = new ProductAttribute()
                {
                    Description = "aabbb"
                }
            }
        }
    });
    context.SaveChanges();
}

using (var context = new TableSplittingContext(contextOptions))
{
    var pendingCount = context.Orders.Count();
    Console.WriteLine($"Current number of pending orders: {pendingCount}");
}

using (var context = new TableSplittingContext(contextOptions))
{
    var order = context.ProductAttributes.First();
    Console.WriteLine($"First pending order will ship to: {order.Id}");
}